using System;
using System.Collections; 
using System.Collections.Generic;
public class MissonPool : BasePool
{
	private static MissonPool instance;
	private Dictionary<uint,Misson> mDataList = new Dictionary<uint, Misson>();
	public MissonPool(){
		instance = this;
	}
	public override IEnumerator Init ()
	{
		Misson newObj = new Misson();
		XmlHelper xmlHelper = XmlHelper.GetInstance();
		yield return xmlHelper.StartCoroutine(xmlHelper.getContentsByFiledName(newObj,"Data/Misson"));
		List<object> datas = xmlHelper.alList;
		foreach(object obj in datas){
			newObj = (Misson)obj;
			mDataList.Add(newObj.id,newObj);
			string[] itemList = newObj.itemTypes.Split(',');
			newObj.itemTypeList = new int[itemList.Length];
			for(int i =0;i< itemList.Length;i++){
				newObj.itemTypeList[i] = int.Parse(itemList[i]);
			}
			string[] propList = newObj.props.Split(';');
			newObj.propIdList = new int[propList.Length];
			newObj.propProList = new int[propList.Length];
			
			for(int i = 0;i < propList.Length;i++){
				string[] strs =	propList[i].Split(',');
				newObj.propIdList[i] = int.Parse(strs[0]);
				newObj.propProList[i] = int.Parse(strs[1]);
			}
			
			string[] moneyList = newObj.moneys.Split(';');
			newObj.moneyIdList = new int[moneyList.Length];
			newObj.moneyProList = new int[moneyList.Length];
			
			for(int i = 0;i < moneyList.Length;i++){
				string[] strs =	moneyList[i].Split(',');
				newObj.moneyIdList[i] = int.Parse(strs[0]);
				newObj.moneyProList[i] = int.Parse(strs[1]);
			}
			
			string[] tujianList = newObj.tujians.Split(';');
			newObj.tujianIdList = new int[tujianList.Length];
			newObj.tujianProList = new int[tujianList.Length];
			
			for(int i = 0;i < tujianList.Length;i++){
				string[] strs =	tujianList[i].Split(',');
				newObj.tujianIdList[i] = int.Parse(strs[0]);
				newObj.tujianProList[i] = int.Parse(strs[1]);
			}
			
			newObj.starScoreList = new int[3];
			newObj.starScoreList[0] = newObj.starScore1;
			newObj.starScoreList[1] = newObj.starScore2;
			newObj.starScoreList[2] = newObj.starScore3;
			newObj.starTimeList = new int[3];
			newObj.starTimeList[0] = newObj.starTime1;
			newObj.starTimeList[1] = newObj.starTime2;
			newObj.starTimeList[2] = newObj.starTime3;
		}
		yield break;
	}
	public static Misson GetMisson(uint id){
		if(instance.mDataList.ContainsKey(id)){
			return instance.mDataList[id];
		}else{
			throw new Exception("Not Find Hero Data,id = "+id+"!");
		}
	}
	public static List<Misson> GetAllMisson(){
		List<Misson> dataList = new List<Misson>();
		foreach(Misson data in instance.mDataList.Values){
			dataList.Add(data);
		}
		return dataList;
	}
}


